home *** CD-ROM | disk | FTP | other *** search
/ Hardcore Visual Basic 5.0 (2nd Edition) / Hardcore Visual Basic 5.0 - Second Edition (1997)(Microsoft Press).iso / Code / gditool.cls < prev    next >
Text File  |  1997-06-14  |  2KB  |  82 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "GGDITool"
  6. Attribute VB_GlobalNameSpace = True
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = True
  10. Option Explicit
  11.  
  12. Public Enum EErrorGDITool
  13.     eeBaseGDITool = 13510   ' GDITool
  14. End Enum
  15.  
  16. Function VBPolygon(ByVal hDC As Long, aPoint() As Long) As Boolean
  17.     Dim apt() As POINTL, i As Long, iMin As Long, c As Long
  18.     iMin = LBound(aPoint)
  19.     c = UBound(aPoint) - iMin + 1
  20.     BugAssert 0 = (c Mod 2)     ' Even number of elements
  21.     c = c / 2
  22.     ' Create array of pixel-adjusted points
  23.     ReDim apt(0 To c - 1) As POINTL
  24.     Do While i < c
  25.         apt(i).x = aPoint(iMin) / Screen.TwipsPerPixelX
  26.         iMin = iMin + 1
  27.         apt(i).y = aPoint(iMin) / Screen.TwipsPerPixelY
  28.         iMin = iMin + 1
  29.         i = i + 1
  30.     Loop
  31.     ' Pass first element and count to Polygon
  32.     VBPolygon = Polygon(hDC, apt(0), c)
  33. End Function
  34.  
  35. Function VBFloodFill(ByVal hDC As Long, ByVal x As Long, _
  36.                      ByVal y As Long, ByVal clr As Long) As Boolean
  37.     VBFloodFill = FloodFill(hDC, x / Screen.TwipsPerPixelX, _
  38.                                  y / Screen.TwipsPerPixelY, clr)
  39. End Function
  40.  
  41. ' Create combined ROP for MaskBlt
  42. Function MakeRop4(ropFore As Long, ropBack As Long) As Long
  43.     ' MakeRop4 = ((ropBack SHL 8) And &HFF000000) Or ropFore
  44. #If 1 Then
  45.     MakeRop4 = (MBytes.LShiftDWord(ropBack, 8) And &HFF000000) Or ropFore
  46. #Else
  47.     ' Hack to do same shift in Basic
  48.     If ropBack And &H800000 Then
  49.         Dim ropTmp As Long
  50.         ' Remove high bit
  51.         ropTmp = (ropBack And &HFF7FFFFF)
  52.         ' Do calculation
  53.         ropTmp = ((ropTmp * 256) And &HFF000000) Or ropFore
  54.         ' Put high bit back in
  55.         MakeRop4 = ropTmp Or &H80000000
  56.     Else
  57.         MakeRop4 = ((ropBack * 256) And &HFF000000) Or ropFore
  58.     End If
  59. #End If
  60. End Function
  61.  
  62. #If fComponent = 0 Then
  63. Private Sub ErrRaise(e As Long)
  64.     Dim sText As String, sSource As String
  65.     If e > 1000 Then
  66.         sSource = App.ExeName & ".GDITool"
  67.         Select Case e
  68.         Case eeBaseGDITool
  69.             BugAssert True
  70.        ' Case ee...
  71.        '     Add additional errors
  72.         End Select
  73.         Err.Raise COMError(e), sSource, sText
  74.     Else
  75.         ' Raise standard Visual Basic error
  76.         sSource = App.ExeName & ".VBError"
  77.         Err.Raise e, sSource
  78.     End If
  79. End Sub
  80. #End If
  81.  
  82.